﻿<?php
define('IN_QY',true);
session_start();
require("include/common.inc.php");
require_once("include/config.php");
require_once("include/httpUtil.php");
define('SCRIPT','ad_list');
$infoid=trim($_GET['fid']);
if(!$_COOKIE['userid']){
    echo "<script type='text/javascript'>location.href='mlogin.php';</script>";
    exit;
}
$sql="select * from tbl_user where id=".$_COOKIE['userid'];
$a=mysql_query($sql);
$rowa=mysql_fetch_array($a);
if($_POST){
    ////
    $vip=$_POST['vip'];
    $jf=$_POST['jf'];
    $vip2=explode('+',$vip);
    $vip3=$vip2['0'];
    $vip4=$vip2['1'];
    if($vip==''){
        echo "<script>alert('请选择兑换方式');window.location.href='jifen3.php';</script>";
        exit;
    }

    if($jf<$vip4){
        echo "<script>alert('积分不足');window.location.href='my.php';</script>";
        exit;
    }
    if($vip3==1){
        $time=1;
        $dji=2;
    }
    if($vip3==2){
        $time=3;
        $dji=2;
    }
    if($vip3==3){
        $time=6;
        $dji=2;
    }

    $yuanexpore=$rowa['vipexpire'];
    $wxopenid=$rowa['wxopenid'];
    $time2=date('Y-m-d H:i:s',strtotime("+$time month",strtotime($yuanexpore)));
    $time3=date('Y-m-d H:i:s',strtotime('+1month'));
    if($yuanexpore==0){
        $sql="update tbl_user set viplevel=".$dji.", vipexpire='".$time3."', jifen=jifen-'".$vip4."' where id=".$_COOKIE['userid'];
    }else{
        $sql="update tbl_user set viplevel=".$dji.", vipexpire='".$time2."', jifen=jifen-'".$vip4."' where id=".$_COOKIE['userid'];
    }
    mysql_query($sql);

//入账
    $sqlyyq = "insert into tbl_vippay values (0, '积分兑换VIP', '".$vip4."''积分兑换VIP''".$dji."''".$time."''个月', , , , , '".date('Y-m-d H:i:s')."', '".$_COOKIE['userid']."',0,
0,0)";
    mysql_query($sqlyyq);

//短信发送开始--支付成功了
    $funAndOperate = "industrySMS/sendSMS";
// 生成body
    $body = createBasicAuthData();
// 在基本认证参数的基础上添加短信内容和发送目标号码的参数
    $body['smsContent'] = '【众晒网】亲爱的'.$_COOKIE['shuyu'].'，您已成功消费'.$vip4.'积分，感谢您的支持';
    $body['to'] = ''.$_COOKIE['username'].'';
    $result = post($funAndOperate, $body);
    //短信发送结束


    //jies微信公众号推送消息
    if(($wxopenid!="") || ($wxopenid!=0)){  //判断微信id不为0 不为空时才发送微信推送
        $shijian=date("Y-m-d H:i:s",$rowb['lastjiaofei']);
        $ac = file_get_contents('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxd6671ed64906b4b4&secret=04b2aa5188bde40a5adecb5fbaea226a');
        $wxt = json_decode($ac,true);
        $url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='.$wxt['access_token'];//access_token改成你的有效值

        $data = [
            'touser' => $wxopenid,
            'template_id' => 'Ljcp07HmSo8C8nEKLw_lPqnyRA2igWWlyZ7kjAtXuTQ',
            'url' => 'www.goodshare.com.cn/wap/',
            'data' => [
                'first' => [
                    'value' => '亲，恭喜您的vip兑换成功',
                    'color' => '#173177',
                ],
                'keyword1' => [
                    'value' => '尊贵VIP',
                    'color' => '#173177',
                ],
                'keyword2' => [
                    'value' => $time2,
                    'color' => '#173177',
                ],
                'remark' => [
                    'value' => '请点击详情查看，如有疑问联系客服',
                    'color' => '#173177',
                ]
            ]
        ];
        $access_token = $wxt['access_token'];
        $params = json_encode($data,JSON_UNESCAPED_UNICODE);
        $start_time = microtime(true);
        for ($i = 0; $i < 1; $i++) {
            $fp = fsockopen('api.weixin.qq.com', 80, $error, $errstr, 1);
            $http = "POST /cgi-bin/message/template/send?access_token={$access_token} HTTP/1.1\r\nHost: api.weixin.qq.com\r\nContent-type: application/x-www-form-urlencoded\r\nContent-Length: " . strlen($params) . "\r\nConnection:close\r\n\r\n$params\r\n\r\n";
            fwrite($fp, $http);
            fclose($fp);
        }
    }
//jies

    echo "<script>alert('兑换成功，祝您愉快');window.location.href='my.php';</script>";
}
?>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title><?=$_COOKIE['shuyu']?>/成为G·S尊享会员-众晒网</title>
    <link rel="stylesheet" type="text/css" href="/ui/css/Hui.css" />
	<script src="/ui/layer/mobile/layer.js"></script>
    <style type="text/css">
        #header{width:100%; position:absolute; top:0;}
        #lis{width:100%; overflow: auto; position:absolute; top:45px;bottom:0px;}
        li{border:1px solid gray;margin-top:10px;padding:8px;}
        .mu .liSelected{background-color:#EECBAD;border-color:#EE7942;}
        .mu li:hover{background-color:#EECBAD;border-color:#EE7942;}

    </style>
</head>
<body class="H-flexbox-vertical" >
<header class="H-header H-theme-background-color-white" id="header">
    <span tapmode="" onclick="H.closeWin();" class="H-icon H-position-relative H-display-inline-block H-float-left H-vertical-middle H-theme-font-color-white H-padding-horizontal-left-5 H-z-index-100"><i class="H-iconfont H-theme-font-color-black H-icon-arrow-left H-font-size-18 H-vertical-middle"></i></span>
    <div class="H-header-title H-center-all H-font-size-18 H-text-show-row-1 H-theme-font-color-black H-position-absolute H-width-100-percent H-theme-background-white">
        成为 G·S尊享会员
    </div>
</header>
<div id="lis" class="H-padding-8" style="width:95%;">

    <div id="list1" class="H-border-radius3-px H-theme-background-color-white H-margin-vertical-bottom-5 H-border-vertical-both-after H-border-horizontal-both-after" >
        <div class="H-flexbox-horizontal H-theme-background-color-white H-border-vertical-bottom-after">
            <div class="H-padding-vertical-both-10">
                <img src="<?=$rowa['username']?>" srcs="" alt="" title="" class="imgCache H-display-block  H-margin-horizontal-left-10 H-border-radius-circle" style="width: 40px; height: 40px;" />
            </div>
            <div class="H-flex-item H-padding-10">

                <div class="H-font-size-14 H-theme-font-color-999 H-text-show-row-2">
                        <span><?=$_COOKIE['shuyu']?>
						</span>

                </div>
                <div class="H-font-size-12 H-theme-font-color-999 H-text-show-row-2">
                    当前积分:<?=$rowa['jifen']?> 
                </div>
            </div>
        </div>
    </div>
    <!-- vip等级续费 --> 
    <!-- v1 -->
    <div class="H-channel-title H-flexbox-horizontal H-theme-background-color-white H-vertical-middle H-border-vertical-bottom-after">
        <div class="H-channel-line H-theme-background-color8 H-padding-vertical-top-15 H-padding-horizontal-left-3  H-margin-horizontal-left-10"></div>
        <div class="H-channel-text H-theme-font-color8 H-flex-item H-font-size-18 H-theme-font-color-black H-padding-10 H-margin-horizontal-right-10 H-text-show-row-1">G·S尊享会员</div>
    </div>
    <!-- v1 -->
    <div class="H-accordion-area">

		                <div id="mu" class="mu H-padding-10 H-border-vertical-bottom-after  H-theme-background-color-white H-flexbox-horizontal H-theme-font-color-black H-font-size-14 H-flexbox-horizontal H-text-horizontal-left H-box-sizing-border-box" >
                    <ul style="width:97%"  id="ull">
					
								  <?php
			  
        $sql2 = "select * from tbl_taospp  where goodstype >3 AND vip_stage=1 order by id asc ";
        $query2=mysql_query($sql2);

		while ($row2=mysql_fetch_array($query2)) {    
      
    ?> 

                        <li value="<?=$row2['id']?>+<?=$row2['pay_score']?>" >
                            <span><?=$row2['chtitle']?></span><br/>
                            <span class="H-theme-font-color-999"><?=$row2['pay_score']?> 积分兑换</span>
                        </li>		
	  <?php } ?>


                    </ul>
                </div>
		
		
		
    </div>
    <!-- v2 -->
    <!-- v2 -->

    <!-- v2 -->
    </br>	</br>	</br>

		        <input type="hidden" name="goodsid" id="goodsid" >
		   
			   
    <div class="H-padding-10 H-border-vertical-bottom-after  H-theme-background-color-white H-flexbox-horizontal H-theme-font-color-999 H-font-size-14 H-footer H-flexbox-horizontal H-text-horizontal-left H-box-sizing-border-box" style="width:96%;height:50px;position:fixed;bottom:0px">
                <span class="H-display-block H-font-size-16 H-flex-item H-theme-font-color-black-active">
                        <span>总价：</span> <b><sapn style="color:#EE7942"><input type="text" readonly="readonly" id="jiage" style="width:50px;border:none"/></sapn></b>
                        <input type="hidden" readonly="readonly" id="jiage1" name='vip'>
                        <input type="hidden"  name='jf' value="<?=$rowa['jifen']?>">
                        <button type="button" onclick="addjf()" class="H-button H-width-100-percent H-font-size-18 H-outline-none H-padding-vertical-both-7 H-padding-horizontal-both-17 H-theme-background-color8 H-theme-font-color-white H-theme-border-color8 H-theme-border-color8-click H-theme-background-color8-click H-theme-font-color8-click H-border-radius-3" style="width:33%;float:right;margin-right:10px">确认兑换</button>
                 </span>
    </div>

</div>

<script type="text/javascript" src="/ui/js/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="/ui/script/H.js"></script>
<script type="text/javascript">
    var mu = document.getElementById("mu");
    var li = mu.getElementsByTagName("li");
    mu.onclick = function(e){
        e = e || window.event;
        var target = e.srcElement || e.target;
        for(var i=0,len=li.length;i<len;i++){
            li[i].className = target == li[i] ? "liSelected":"";
        }
    };
</script>
<script type="text/javascript">
    $(function(){
        $("#ull li").on("click",function(){   //核心代码
            var a=$(this).attr("value");    //获取每个li的value值
			var d=a.split('+');
            var b=d[1];
            var c=d[0];;			
            $("#jiage1").val(a);
            $("#jiage").val(b);
            $("#goodsid").val(c);
			
        });
    });
	
	
	function addjf(){
		var goodsid = $("#goodsid").val();	
		
		
		
		if(goodsid==""){
		
	layer.open({
    content: '请先选择兑换时间'
    ,skin: 'msg'
    ,time: 2 //2秒后自动关闭
  });	
	return false;	
	}	

		var uid = '<?=$_COOKIE['userid']?>';
		var pay_type='1';
		$.ajax({
        url: '/api/muyin/api.php?s=user.pay_vip_use_score',
        type: 'POST',
        dataType: 'json',
        data: {goodsid: goodsid,
		uid:uid,
		pay_type:pay_type
		},
      })
      .done(function(respon) {
        if (respon.code==0) {
 				 alert('兑换成功，祝您愉快');	 

				location.reload() ; 
				window.location.href="my.php";
				
        }else{
          

 alert('兑换失败，检查是否积分不足');	

		  
        }
      }) 		
		
		
	}
	
</script>

<script type="text/javascript">
    H.on(H.Ds(".H-accordion-title"), "touchend", function (event) {
        var area = H.getParents(event.target, "H-accordion-area");
        var title = H.D(".H-accordion-title", area);
        var main = H.D(".H-accordion-main", area);
        var icon = H.D(".H-accordion-icon", area);
        if (H.isElement(main)) {
            if (H.hasClass(main, "H-display-none-important")) {

                H.removeClass(icon, "H-icon-arrow-down");
                H.addClass(icon, "H-icon-arrow-up");

                H.removeClass(title, "H-theme-background-color-white");
                H.addClass(title, "H-theme-background-color-f4f4f4");

                H.removeClass(main, "H-display-none-important");
            }
            else {
                H.removeClass(icon, "H-icon-arrow-up");
                H.addClass(icon, "H-icon-arrow-down");

                H.removeClass(title, "H-theme-background-color-f4f4f4");
                H.addClass(title, "H-theme-background-color-white");

                H.addClass(main, "H-display-none-important");
            }
        }
    });
</script>
</body>
</html>